package com.reflect;

import com.annotation.MyAnnotation;
import com.bean.MyBean;

import java.lang.annotation.Annotation;

/**
 * @author: 一个小菜逼
 * @Date: 2020/4/28
 */
public class MyReflectAnnotation {

    public static void main(String[] args) {
        Class<MyBean> myBeanClass = MyBean.class;
        //获取该类上面的所有注解
        Annotation[] annotations = myBeanClass.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        //获取指定类型的注解，注解本质上应该就是个类，因为后面有.class，猜的
        MyAnnotation annotation = myBeanClass.getAnnotation(MyAnnotation.class);
        //获取注解中指定属性的值，这个value是注解中自己定义的属性
        String value = annotation.value();
        String s = annotation.myValue();
        System.out.println(value+","+s);
    }
}
